package com.goodluck.goodluckim.ui.session.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.goodluck.goodluckim.R;
import com.goodluck.goodluckim.sdk.constant.MsgType;
import com.goodluck.goodluckim.db.model.RecentSession;
import com.goodluck.goodluckim.ui.session.helper.SessionHelper;
import com.goodluck.goodluckim.widget.emoji.MoonUtil;

import java.util.List;

/**
 * Created by wyj on 2018/9/12.
 */

public class SessionAdapter extends BaseQuickAdapter<RecentSession, BaseViewHolder> {
    public SessionAdapter(@Nullable List<RecentSession> data) {
        super(R.layout.listitem_recent_session, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecentSession item) {
        TextView titleTv = helper.getView(R.id.title_tv);
        if (TextUtils.isEmpty(item.getObjectName())) {
            titleTv.setText(SessionHelper.getRecentCustomization().getDefaultTitle(item));
        } else {
            titleTv.setText(item.getObjectName());
        }

        TextView contentTv = helper.getView(R.id.content_tv);
        if (item.getMessageType() == MsgType.TEXT) {
            MoonUtil.identifyFaceExpression(mContext, contentTv, SessionHelper.getRecentCustomization().getDefaultDigest(item), ImageSpan.ALIGN_BOTTOM);
            contentTv.setMovementMethod(LinkMovementMethod.getInstance());
        } else {
            contentTv.setText(SessionHelper.getRecentCustomization().getDefaultDigest(item));
        }
    }
}
